<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    // "use strict";
    // 节流
    // function fn(ev){
    //     console.log(ev);
    //     console.log('我触发了');
    // }
    // document.onmousemove = fn


    // 定义一个节流函数
    function throttled(fn,delay){
      let timer = null //先给timer一个初始值null
      return function(...arg){
          
        if(!timer){
            timer = setTimeout(()=>{
                 console.log(this);//document
                fn.apply(null,arg)//，调用操作函数,apply就是更改this指向的
                // fn()
                timer = null
            },1000)
        }
      }
    }
    // 操作
    function fn(ev){
        console.log(this);//document
        console.log('我触发了');
        console.log(ev);
    }
    document.onmousemove = throttled(fn,1000)

    // 给节流函数传递参数
    // let thFn = throttled(fn,1000)
    // document.onmousemove = function(){
    //     thFn('ertyuiop')
    // }


</script>
</html>